package com.example.administrator.fastdream.date.presenter;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

import com.example.administrator.fastdream.date.bean.APayBean;
import com.example.administrator.fastdream.date.bean.WXBean;
import com.example.administrator.fastdream.date.http.JsonCallback;
import com.example.administrator.fastdream.date.utils.CacheUtils;
import com.example.administrator.fastdream.date.utils.MyUrl;
import com.example.administrator.fastdream.view.activity.LoginActivity;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;

public class WeCountPresenter {
    private Activity mActivity;
    private DataCallBack loginCallBack;

    public WeCountPresenter(Activity activity, DataCallBack loginCallBack) {
        this.mActivity = activity;
        this.loginCallBack = loginCallBack;
    }

    public void data(String issue,String pay_money,String lucky_number,String pay_type) {
        HttpParams params = new HttpParams();
        params.put("user_token", (String) CacheUtils.get("token"));
        params.put("issue", issue);
        params.put("lucky_number", lucky_number);
        params.put("pay_money", pay_money);
        params.put("pay_type", pay_type);
        OkGo.<WXBean>post(MyUrl.BASEURL + "Home/add_order")
                .tag(this)
                .params(params)
                .execute(new JsonCallback<WXBean>(WXBean.class) {
                    @Override
                    public void onSuccess(Response<WXBean> response) {
                        if (response.body() == null) {
                            return;
                        }
                        String status = response.body().getStatus();
                        if (status.equals("1")) {
                            loginCallBack.date(response.body());
                        } else if (status.equals("2")) {
                            Toast.makeText(mActivity, response.body().getMessage(), Toast.LENGTH_SHORT).show();
                        } else {
                            mActivity.startActivity(new Intent(mActivity, LoginActivity.class));
                        }
                    }
                });
    }

    public interface DataCallBack {
        void date(WXBean dataBean);
    }
}
